/**
 * 首页
 * @author yaohuan
 * @date 2019/03/19
 */
define(['plugins/echarts/echarts.min'],function (echarts) {

    var self,
        app = win.app,
        list = [],//1、组织公告；
        channelList = [], //2、渠道公告；
        DistributorList = [], //3、经销商公告
        imgList1 = [], //产品展示
        imgList2 = [],
        shopping = [],
        list = [],
        swiper, swiper2, swiper3;


    var Admin = app.Module.extend({
        init: function () {
            self = this;
            self._super({
                _loadTplsFull: [
                    {
                        dom: 'notice_detail', tpl: 'system/notice_detail'
                    },
                    {
                        dom: 'common_open_window', tpl: 'common/_open_window'
                    }]
            }, win);
        },
        //初始化数据
        initData: function () {

        },
        _ready: function () {
            new Vue({
                el: '#admin',
                data: {
                    lists: list,
                    cList: channelList,
                    dList: DistributorList,
                    imgLists1: imgList1,
                    imgLists2: imgList2,
                    activeName2: 'first',
                    currentPage: 0,
                    currentPage2: 0,
                    currentPage3: 0,
                    currentPage4: 0,
                    pageSize: 5,
                    pageSize4: 100,
                    total4: 0,
                    pageData: [],
                    pageData2: [],
                    pageData3: [],
                    pageData4: [],
                    formInline: {
                        GWAM001: '',
                        GWAML004: '',
                        GWDC001: '',
                        GWAK061: '',
                        GWAM004: '',
                        GWAM004_NAME: '',
                        GWAM007: '',
                        GWAM007_NAME: '',
                        GWAK001: '',
                        GWAKL003: '',
                        GWAK010: ''
                    },
                    disabled: false,
                    hidden: false,
                    shopping: shopping,
                    list: []
                },
                methods: {
                    loadMsgList3() {
                        let that = this;
                        //list分页请求
                        app.ajax({
                            xdata: {
                                GWDH002: '3'
                            },
                            xurl: "admin/getNotices",
                            cb: function (result) {
                                if (result.ok) {
                                    that.dList = result.data.data;
                                    that.nextPage3();
                                }
                            }
                        });
                    },
                    loadMsgList2() {
                        let that = this;
                        //list分页请求
                        app.ajax({
                            xdata: {
                                GWDH002: '2'
                            },
                            xurl: "admin/getNotices",
                            cb: function (result) {
                                if (result.ok) {
                                    that.cList = result.data.data;
                                    that.nextPage2();
                                }
                            }
                        });
                    },

                    loadMsgList() {
                        let that = this;
                        //list分页请求
                        app.ajax({
                            xdata: {
                                GWDH002: '1'
                            },
                            xurl: "admin/getNotices",
                            cb: function (result) {
                                if (result.ok) {
                                    that.lists = result.data.data;
                                    that.nextPage();
                                }
                            }
                        });
                    },
                    prevPage: function () {
                        if (this.lists.length > 0) {
                            if (this.currentPage > 1) {
                                this.currentPage--;
                            } else {
                                app.showWarning('没有上一页了');
                                return;
                            }
                            var start = (this.currentPage - 1) * this.pageSize;
                            var end = start + this.pageSize;
                            if (end > this.lists.length) {
                                end = this.lists.length;
                            }
                            this.pageData.splice(0, this.pageSize);
                            for (var i = start; i < end; i++) {
                                this.pageData.push(this.lists[i]);
                            }
                        }
                    },
                    nextPage: function () {
                        if (this.lists.length > 0) {
                            if (this.currentPage * this.pageSize < this.lists.length) {
                                this.currentPage++;
                            } else {
                                app.showWarning('没有下一页了');
                                return;
                            }
                            var start = (this.currentPage - 1) * this.pageSize;
                            var end = start + this.pageSize;
                            if (end > this.lists.length) {
                                end = this.lists.length;
                            }
                            this.pageData.splice(0, this.pageSize);
                            for (var i = start; i < end; i++) {
                                this.pageData.push(this.lists[i]);
                            }
                        }
                    },
                    prevPage2: function () {
                        if (this.cList.length > 0) {
                            if (this.currentPage2 > 1) {
                                this.currentPage2--;
                            } else {
                                app.showWarning('没有上一页了');
                                return;
                            }
                            var start = (this.currentPage2 - 1) * this.pageSize;
                            var end = start + this.pageSize;
                            if (end > this.cList.length) {
                                end = this.cList.length;
                            }
                            this.pageData2.splice(0, this.pageSize);
                            for (var i = start; i < end; i++) {
                                this.pageData2.push(this.cList[i]);
                            }
                        }
                    },
                    nextPage2: function () {
                        if (this.cList.length > 0) {
                            if (this.currentPage2 * this.pageSize < this.cList.length) {
                                this.currentPage2++;
                            } else {
                                app.showWarning('没有下一页了');
                                return;
                            }
                            var start = (this.currentPage2 - 1) * this.pageSize;
                            var end = start + this.pageSize;
                            if (end > this.cList.length) {
                                end = this.cList.length;
                            }
                            this.pageData2.splice(0, this.pageSize);
                            for (var i = start; i < end; i++) {
                                this.pageData2.push(this.cList[i]);
                            }
                        }
                    },
                    prevPage3: function () {
                        if (this.dList.length > 0) {
                            if (this.currentPage3 > 1) {
                                this.currentPage3--;
                            } else {
                                app.showWarning('没有上一页了');
                                return;
                            }
                            var start = (this.currentPage3 - 1) * this.pageSize;
                            var end = start + this.pageSize;
                            if (end > this.dList.length) {
                                end = this.dList.length;
                            }
                            this.pageData3.splice(0, this.pageSize);
                            for (var i = start; i < end; i++) {
                                this.pageData3.push(this.dList[i]);
                            }
                        }
                    },
                    nextPage3: function () {
                        if (this.dList.length > 0) {
                            if (this.currentPage3 * this.pageSize < this.dList.length) {
                                this.currentPage3++;
                            } else {
                                app.showWarning('没有下一页了');
                                return;
                            }
                            var start = (this.currentPage3 - 1) * this.pageSize;
                            var end = start + this.pageSize;
                            if (end > this.dList.length) {
                                end = this.dList.length;
                            }
                            this.pageData3.splice(0, this.pageSize);
                            for (var i = start; i < end; i++) {
                                this.pageData3.push(this.dList[i]);
                            }
                        }
                    },
                    prevPage4: function () {
                        if (this.shopping.length > 0) {
                            if (this.currentPage4 > 1) {
                                this.currentPage4--;
                            } else {
                                app.showWarning('没有上一页了');
                                return;
                            }
                            var start = (this.currentPage4 - 1) * this.pageSize4;
                            var end = start + this.pageSize4;
                            if (end > this.shopping.length) {
                                end = this.shopping.length;
                            }
                            this.pageData4.splice(0, this.pageSize4);
                            for (var i = start; i < end; i++) {
                                this.pageData4.push(this.shopping[i]);
                            }
                        }
                    },
                    nextPage4: function () {
                        if (this.shopping.length > 0) {
                            if (this.currentPage4 * this.pageSize4 < this.shopping.length) {
                                this.currentPage4++;
                            } else {
                                app.showWarning('没有下一页了');
                                return;
                            }
                            var start = (this.currentPage4 - 1) * this.pageSize4;
                            var end = start + this.pageSize4;
                            if (end > this.shopping.length) {
                                end = this.shopping.length;
                            }
                            this.pageData4.splice(0, this.pageSize4);
                            for (var i = start; i < end; i++) {
                                this.pageData4.push(this.shopping[i]);
                            }
                        }
                    },
                    open: function (item) {
                        self._openTplFull({
                            tag: 'notice_detail',
                            tagData: item.GWDHDOCNO,
                            index: 0,
                            openOpts: {
                                title: '公告资料详情',
                                maxmin:true
                                // area: ['700px', '500px']
                            }
                        });
                    }
                },
                mounted: function () {
                    this.loadMsgList();
                    this.loadMsgList2();
                    this.loadMsgList3();
                },
                updated: function () {
                    if (this.activeName2 == 'first') {
                        $('#rightBtn2').css('display', 'none');
                        $('#rightBtn').css('display', 'block');
                        let nextbtn = $('#rightBtn');
                        let headLayout = $('.el-tabs__nav-scroll');
                        nextbtn.prependTo(headLayout);
                    } else if (this.activeName2 == 'second') {
                        $('#rightBtn').css('display', 'none');
                        $('#rightBtn2').css('display', 'block');
                        let nextbtn = $('#rightBtn2');
                        let headLayout = $('.el-tabs__nav-scroll');
                        nextbtn.prependTo(headLayout);
                    }
                }
            });
            self.initData(1);


        },
        _lazy: function () {
            this._super();

        }
    });

    return new Admin();

});
